import {h} from 'vue'
import {Component} from "vue/dist/vue";
import {NIcon} from "naive-ui";
import router from "../router";

export  const renderIcon = (icon: Component) => {
    return () => h(NIcon, null, { default: () => h(icon) })
}


// 递归组装菜单格式

export function generatorMenu(routerMap:Array<any>){

    routerMap.sort((a,b)=> a.meta.sort - b.meta.sort)
    let result = routerMap.map((item)=>{

        let menu = {
            label:item?.meta?.title,
            key:item?.name,
            icon:item.meta?.icon,
            // children:item.children

        }
        if (item.children && item.children.length>1){
            menu.children = generatorMenu(item.children)
        }else if(item.children && item.children.length === 1){
            menu.key = item?.children[0].name
        }
        return menu

    })
    return result

}
// export function isRootRouter(item):Boolean {
//     return  item.children?.length === 1;
// }